<template>
    <div>
        <van-button v-if="!detaile.is_followed" @click="followed" :color="detaile.is_followed?'rgb(252,102,39)':'#fc6627'" class="gz" size="small" icon="plus"  round >关注</van-button>
        <van-button v-else-if="detaile.is_followed" @click="caclefollowed" type="default" class="gz" size="small"  round >已关注</van-button>
    </div>
</template>
<script>
import {
    starauthor,
    caclestarauthor,
} from '@/api/article'
export default {
    name:'focusBtn',
    props:{
        detaile:{
            required:true,
            type:Object
        },
        type:{
            type:String,
            default:'default'
        }
    },
    data(){
        return{
            
        }
    },
    methods:{
        async followed(){
            try{
                const {data}= await starauthor(this.detaile.aut_id)
                if(data.message=='OK'){
                    this.$toast('关注成功！')
                    this.detaile.is_followed=true
                }else{
                    this.$toast('系统错误')
                }
                
            }catch(err){
                this.$toast('操作失败')
            }
        },
        async caclefollowed(){
            const {status}= await caclestarauthor(this.detaile.aut_id)
            if(status=='204'){
                this.$toast('取消关注！')
                this.detaile.is_followed=false
                if(this.type=='focus_fans'){
                    this.$bus.$emit('clickfocus')
                }
            }else{
                this.$toast('系统错误')
            }
            
        },
    },
    created(){
        if(this.type=='focus_fans'){this.detaile.aut_id=this.detaile.id;this.detaile.is_followed=true}
    }
}
</script>
<style lang="less" scoped>
/deep/.gz .van-button__icon{
    font-size:10px
}
/deep/.van-field__control{
    background-color:#ededed;
    padding:10px 20px;
    color:black;
    font-size: .4rem;
}
</style>